﻿using System.Drawing;

namespace DemoForSnake
{
    //食物类
    public class Bean
    {
        //用于画食物的顶端坐标
        private Point _origin;
        public Rectangle Rectangle { get; set; }
        public Point Origin
        {
            get { return _origin; }
            set { _origin = value; }
        }

        public Bean()
        {
            //初始化
            Rectangle = new Rectangle(); 
        }
        public Rectangle rec;
        //显示食物
        public void ShowBean(Graphics g)
        {
            rec = new Rectangle(Origin.X, Origin.Y, 15, 15);
            g.DrawImage(Properties.Resources.bean, rec);
        }
        public void UnShowBean(Graphics g)
        {
            //定义系统背景颜色的画笔
            SolidBrush brush = new SolidBrush(Color.Silver);
            //画实心矩形颜色为系统背景颜色，食物被吃掉了
            g.FillRectangle(brush, Origin.X, Origin.Y, 15, 15);
        }
    }
}
